<?php
require_once '../../include/common.inc.php';
require_once '../function.php';
if(stripos(auth_group($_SESSION['login_gid']),'users_admin')===false)exit("没有权限！");
$auth_rule_userdel=false;
if(stripos(auth_group($_SESSION['login_gid']),'users_del')!==false)$auth_rule_userdel=true;

switch($act){
	case "user_del":
		if(stripos(auth_group($_SESSION['login_gid']),'users_del')===false)exit("没有权限！");
		  if(is_array($id)){
                  user_del(implode(',',$id));
                }
		else{
                       user_del($id);
                }
		header("location:?gid=".$gid);
	break;
}

$query=$db->query("select id,title from {$tablepre}auth_group order by id desc");
while($row=$db->fetch_row($query)){
	$group.='<option value="'.$row[id].'">'.$row[title].'</option>';
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../assets/css/bs3/dpl-min.css" rel="stylesheet" type="text/css" />
<link href="../assets/css/bs3/bui-min.css" rel="stylesheet" type="text/css" />
<link href="../assets/css/page-min.css" rel="stylesheet" type="text/css" />
<!-- 下面的样式，仅是为了显示代码，而不应该在项目中使用-->
<link href="../assets/css/prettify.css" rel="stylesheet" type="text/css" />
<style type="text/css">
code { padding: 0px 4px; color: #d14; background-color: #f7f7f9; border: 1px solid #e1e1e8; }
</style>
<script>
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
function ftime(time){
	if(time==null || time=='') {
		return '';
	}
	return new Date(time*1000).Format("yyyy-MM-dd hh:mm"); ;
}
function ftime2(time){
	if(time>(60*60*24)) return parseInt(time/(60*60*24))+"天";
	else if(time>(60*60))return parseInt(time/(60*60))+"小时";
	else if(time>60)return parseInt(time/60)+"分钟";
	else return parseInt(time)+"秒";
}
function sgid(id){
	var arr=new Array();
	if(isNaN(id)) return '';
	<?php
	$query=$db->query("select * from {$tablepre}auth_group order by id desc");
while($row=$db->fetch_row($query)){
	echo "arr['{$row[id]}']='$row[title]';";
	}
	?>
	return arr[id];
}
</script>
</head>
<body>
<div class="container"  style=" min-width:1400px;">
<form  class="form-horizontal" action="" method="get">
    <form action="" method="POST" enctype="application/x-www-form-urlencoded"  class="form-horizontal" id="hd_list">
  <div style="color:red;">注意: 1 在线会员的统计有5-10分钟的统计误差; 2 每个用户每次登陆后在线时间的统计有3分钟的统计误差; 3 总在线时间在每日夜间12:59分累加今日在线时间形成汇总;</div>
  <table class="table table-bordered table-hover definewidth m10">
    <thead>
      <tr style="font-weight:bold" >
        <td width="40" align="center" bgcolor="#FFFFFF">编号</td>
        <td width="80" align="center" bgcolor="#FFFFFF">用户名</td>
        <td width="80" align="center" bgcolor="#FFFFFF">昵称</td>
        <!--td width="80" align="center" bgcolor="#FFFFFF">手机</td>
		<td width="80" align="center" bgcolor="#FFFFFF">实名</td>
        <td width="60" align="center" bgcolor="#FFFFFF">用户组</td-->
        <td width="50" align="center" bgcolor="#FFFFFF">今日在线</td>
        <td width="50" align="center" bgcolor="#FFFFFF">总在线</td>
        <td width="100" align="center" bgcolor="#FFFFFF">最近活动时间</td>
        <td width="100" align="center" bgcolor="#FFFFFF">最近登录</td>
        <td width="100" align="center" bgcolor="#FFFFFF">注册时间</td>
        <td width="100" align="center" bgcolor="#FFFFFF">注册IP</td>
      </tr>
    </thead>
<?php

$sql="select a.uid, a.username, a.realname,a.fuser, a.tuser, a.gid, a.regdate, a.regip, a.totalonlinetime, a.onlinetime, a.phone, a.lastlogin, a.lastactivity, c.nickname, c.logins from chat_members a, chat_memberfields c where a.uid = c.uid and a.uid!=0 and a.gid=1";

$nowTime = new DateTime();
$beginOfToday = $nowTime->format('Y-m-d').' 00:00:00';
$stime = strtotime($beginOfToday);
$sql.=" and a.lastlogin>'$stime'";

if($_SESSION['login_gid']=='3'){
	// begin 特殊配置, 管理员体系
	if($_SESSION['login_user']=='萧菲') {
		$sql.=" and 1=1 ";
	}
	else if($_SESSION['login_user']=='sunxing007') {
		$sql.=" and a.fuser in ('sunxing007','168118','168110','168111')";
	}
	else if($_SESSION['login_user']=='168112') {
		$sql.=" and a.fuser in ('168112','168118','168110','168111')";
	}
	else if($_SESSION['login_user']=='168114') {
		$sql.=" and a.fuser in ('168114','168115','168116')";
	}
	// END 特殊配置, 管理员体系
	else {
		$sql.=" and a.fuser='".$_SESSION['login_user']."'";
	}
	
}

$sql.=" order by a.onlinetime desc";
echo userlist(500,$sql,'
    <tr>
      <td bgcolor="#FFFFFF" align="center">{uid}</td>
      <td align="center" bgcolor="#FFFFFF">{username}</td>
      <td align="center" bgcolor="#FFFFFF">{nickname}</td>
	  <!--td align="center" bgcolor="#FFFFFF">{phone}&nbsp;</td>
	  <td align="center" bgcolor="#FFFFFF">{realname}&nbsp;</td>
      <td align="center" bgcolor="#FFFFFF"><script>document.write(sgid({gid})); </script>&nbsp;</td-->
      <td align="center" bgcolor="#FFFFFF"><script>document.write(ftime2({onlinetime})); </script></td>
      <td align="center" bgcolor="#FFFFFF"><script>document.write(ftime2({totalonlinetime})); </script></td>
      <td align="center" bgcolor="#FFFFFF"><script>document.write(ftime({lastactivity})); </script></td>
      <td align="center" bgcolor="#FFFFFF"><script>document.write(ftime({lastlogin})); </script></td>
      <td align="center" bgcolor="#FFFFFF"><script>document.write(ftime({regdate})); </script></td>
      <td align="center" bgcolor="#FFFFFF">{regip}<br><a class="linkGetRegIpInfo" ip="{regip}" href="javascript:;">详情</a></td>
    </tr>
')?>

  </table>
    </form>
    <ul class="breadcrumb">
    <li class="active"><?=$pagenav?>
    </li>
  </ul>
</div>
<script type="text/javascript" src="../assets/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="../assets/js/bui.js"></script>
<script type="text/javascript" src="../assets/js/config.js"></script>
<script type="text/javascript" src="../../upload/swfupload/swfupload.js"></script>
<script>
BUI.use('bui/overlay',function(Overlay){
            dialog = new Overlay.Dialog({
            title:'用户设置',
            width:630,
            height:600,
            buttons:[],
            bodyContent:''
          });
});
function openUser(id,type){
	dialog.set('bodyContent','<iframe src="user_edit.php?id='+id+'&type='+type+'" scrolling="yes" frameborder="0" height="100%" width="100%"></iframe>');
	dialog.updateContent();
	dialog.show();
}
function addUser(){
  dialog.set('bodyContent','<iframe src="user_add.php" scrolling="yes" frameborder="0" height="100%" width="100%"></iframe>');
  dialog.updateContent();
  dialog.show();
}

BUI.use('bui/calendar',function(Calendar){
          var datepicker = new Calendar.DatePicker({
            trigger:'#stime',
			showTime : true,
            dateMask : 'yyyy-mm-dd HH:MM:ss',
            autoRender : true
          });
 
var datepicker1 = new Calendar.DatePicker({
            trigger:'#etime',
            showTime : true,
            dateMask : 'yyyy-mm-dd HH:MM:ss',
            autoRender : true
          });
        });
        
$('.linkGetRegIpInfo').click(function(){
	$(this).append('<img src="../../images/loading.gif" />');
	var ip = $(this).attr('ip');
	var p = $(this).parent();
	var linkElement = $(this);
	$.ajax({
		url: 'checkip.php?ip=' + ip,
		success: function(ipinfo){
			if(ipinfo.length < 4) {
				linkElement.html('详情');
				return;
			}
			linkElement.remove();
			p.html(ip + '<br>' + ipinfo);
		}
	})
});
</script>
</body>
</html>
